//
//  DriverCourseVC.m
//  Zhiche-Carriage
//
//  Created by 王亚陆 on 16/6/17.
//  Copyright © 2016年 LeeBruce. All rights reserved.
//

#import "DriverCourseVC.h"
#import <Masonry.h>
#import "Common.h"
#import <MAMapKit/MAMapKit.h>
#import <AMapLocationKit/AMapLocationKit.h>
#import "ActionSheetPicker.h"
#import "area.h"
#define areaTAG 100
#define stateTAG 200
#define arriveTAG 300


#define MySetValue(dict, value) ((!dict[value] || [dict[value] isKindOfClass:[NSNull class]])?@"":dict[value])

#define LocationTimeout 10
#define ReGeocodeTimeout 5


@interface DriverCourseVC ()<AMapLocationManagerDelegate,MAMapViewDelegate>
{
    UIView * nav;
    Common * com;
    area * AREA;
    int holdcount;

}


@property (nonatomic, strong) AMapLocationManager *locationManager;
@property (nonatomic, copy) AMapLocatingCompletionBlock completionBlock;
@property (nonatomic, strong) UILabel *displayLabel;
@property (nonatomic, strong) NSMutableArray * stateArr;
@property (nonatomic, strong) NSMutableArray * arriveArr;
@property (nonatomic, strong) NSMutableArray * holdArr;
@property (nonatomic, strong) NSMutableArray *provienceArray;
@property (nonatomic, strong) NSArray *cityArray;
@property (nonatomic, strong) NSArray *areaArray;

@property (nonatomic, strong) UIButton *stateBtn;
@property (nonatomic, strong) UIButton *placeBtn;
@property (nonatomic, strong) UIButton * destinationBtn;
@property (nonatomic, strong) UIButton * arriveBtn;
@property (nonatomic, strong) UILabel * holdNumber;
@property (nonatomic, strong) NSMutableDictionary * dicUrl;

@end

@implementation DriverCourseVC

- (void)viewDidLoad {
    [super viewDidLoad];
    com = [[Common alloc]init];
    AREA = [[area alloc]init];
    _dicUrl = [[NSMutableDictionary alloc]init];
    holdcount = 1;
    //默认一个仓位
    [_dicUrl setObject:@"1" forKey:@"emptyStore"];
    //默认在途
    [_dicUrl setObject:@"20" forKey:@"status"];
    //默认明天
    NSDate *  senddate=[NSDate date];
    NSCalendar *gregorian = [[NSCalendar alloc] initWithCalendarIdentifier:NSCalendarIdentifierGregorian];
    NSDateComponents *components = [gregorian components:NSCalendarUnitWeekday | NSCalendarUnitYear | NSCalendarUnitMonth | NSCalendarUnitDay fromDate:senddate];
    [components setDay:([components day]+1)];
    
    NSDate *beginningOfWeek = [gregorian dateFromComponents:components];
    NSDateFormatter *dateday = [[NSDateFormatter alloc] init];
    [dateday setDateFormat:@"yyyy/MM/dd"];
    NSString * dataStri = [NSString stringWithFormat:@"%@",[dateday stringFromDate:beginningOfWeek]];;
    
    [_dicUrl setObject:dataStri forKey:@"predictArrive"];
    
    self.view.backgroundColor = WhiteColor;
    nav = [self createNav:@"行程上报"];
    [self.view addSubview:nav];
    
    _stateArr = @[@"在途",@"空闲",@"检修"].mutableCopy;
    _arriveArr = @[@"当天到达",@"明天到达",@"后天到达"].mutableCopy;

//    [self createUI];
    
//    [self initToolBar];
//    [self initNavigationBar];
//    [self configLocationManager];
//    [self initDisplayLabel];
//    [self initCompleteBlock];
//    [self reGeocodeAction];

}
/*

-(void)createUI{
    
    UIView * backview = [[UIView alloc]init];
    backview.backgroundColor = RGBACOLOR(149, 149, 149, 0.5);
    [self.view addSubview:backview];
    [backview mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.view.mas_left);
        make.top.equalTo(nav.mas_bottom).with.offset(0);
        make.size.mas_equalTo(CGSizeMake(Main_Width, 50*kHeight));
    }];

    UILabel * label = [com createUIlabel:@"车辆状态为在途时，目的地和预计到达时间不能为空" andFont:FontOfSize14 andColor:BlackColor];
    [backview addSubview:label];
    [label mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(backview.mas_left).with.offset(20*kWidth);
        make.centerY.equalTo(backview.mas_centerY);
    }];
    
    UILabel * state = [com createUIlabel:@"状态:" andFont:FontOfSize14 andColor:BlackColor];
    state.textAlignment = NSTextAlignmentRight;
    [self.view addSubview:state];
    [state mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.view.mas_left).with.offset(100*kWidth);
        make.top.equalTo(backview.mas_bottom).with.offset(10*kHeight);
    }];
    
    _stateBtn = [com createBtn:@"在途" andFont:FontOfSize14 andTag:1 and:self action:@selector(pressBtn:) andColor:BlackColor];
    _stateBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
    [self.view addSubview:_stateBtn];
    [_stateBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(state.mas_right).with.offset(20*kWidth);
        make.top.equalTo(state.mas_top);
        make.bottom.equalTo(state.mas_bottom);
        make.right.mas_equalTo(self.view.mas_right);
    }];
    //common_list_arrows_more@2x  6  11
    UIImageView * image1 = [[UIImageView alloc]init];
    image1.image = [UIImage imageNamed:@"common_list_arrows_more"];
    [self.view addSubview:image1];
    [image1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.view.mas_right).with.offset(-20*kWidth);
        make.centerY.equalTo(_stateBtn.mas_centerY);
        make.size.mas_equalTo(CGSizeMake(6*kWidth, 11*kHeight));
    }];

    
    UIImageView * imageline1 =[[UIImageView alloc]init];
    imageline1.image = [UIImage imageNamed:@"common_list_line1"];
    [self.view addSubview:imageline1];
    [imageline1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.view.mas_left).with.offset(0);
        make.size.mas_equalTo(CGSizeMake(Main_Width, 0.5));
        make.top.mas_equalTo(state.mas_bottom).with.offset(5*kHeight);
    }];

    _displayLabel = [com createUIlabel:@"当前位置:" andFont:FontOfSize14 andColor:BlackColor];
    _displayLabel.textAlignment = NSTextAlignmentRight;
    [self.view addSubview:_displayLabel];
    [_displayLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.view.mas_left).with.offset(100*kWidth);
        make.top.equalTo(imageline1.mas_bottom).with.offset(10*kHeight);
    }];
    _placeBtn = [com createBtn:@"湖南武汉" andFont:FontOfSize14 andTag:1111 and:self action:nil andColor:BlackColor];
    _placeBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
    [self.view addSubview:_placeBtn];
    [_placeBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(_displayLabel.mas_right).with.offset(20*kWidth);
        make.top.equalTo(_displayLabel.mas_top);
        make.bottom.equalTo(_displayLabel.mas_bottom);
        make.right.mas_equalTo(self.view.mas_right);

    }];
    
    UIImageView * imageline2 =[[UIImageView alloc]init];
    imageline2.image = [UIImage imageNamed:@"common_list_line1"];
    [self.view addSubview:imageline2];
    [imageline2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.view.mas_left).with.offset(0);
        make.size.mas_equalTo(CGSizeMake(Main_Width, 0.5));
        make.top.mas_equalTo(_displayLabel.mas_bottom).with.offset(5*kHeight);
    }];
    UILabel * destination = [com createUIlabel:@"目的地:" andFont:FontOfSize14 andColor:BlackColor];
    destination.textAlignment = NSTextAlignmentRight;
    [self.view addSubview:destination];
    [destination mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.view.mas_left).with.offset(100*kWidth);
        make.top.equalTo(imageline2.mas_bottom).with.offset(10*kHeight);
    }];
    _destinationBtn = [com createBtn:@"点击选择目的地" andFont:FontOfSize14 andTag:2 and:self action:@selector(pressBtn:) andColor:BlackColor];
    _destinationBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
    [self.view addSubview:_destinationBtn];
    [_destinationBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(destination.mas_right).with.offset(20*kWidth);
        make.top.equalTo(destination.mas_top);
        make.bottom.equalTo(destination.mas_bottom);
        make.right.mas_equalTo(self.view.mas_right);

    }];
    UIImageView * image2 = [[UIImageView alloc]init];
    image2.image = [UIImage imageNamed:@"common_list_arrows_more"];
    [self.view addSubview:image2];
    [image2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.view.mas_right).with.offset(-20*kWidth);
        make.centerY.equalTo(_destinationBtn.mas_centerY);
        make.size.mas_equalTo(CGSizeMake(6*kWidth, 11*kHeight));
    }];
    
    UIImageView * imageline3 =[[UIImageView alloc]init];
    imageline3.image = [UIImage imageNamed:@"common_list_line1"];
    [self.view addSubview:imageline3];
    [imageline3 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.view.mas_left).with.offset(0);
        make.size.mas_equalTo(CGSizeMake(Main_Width, 0.5));
        make.top.mas_equalTo(destination.mas_bottom).with.offset(5*kHeight);
    }];
    
    UILabel * arrive = [com createUIlabel:@"预计到达:" andFont:FontOfSize14 andColor:BlackColor];
    arrive.textAlignment = NSTextAlignmentRight;
    [self.view addSubview:arrive];
    [arrive mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.view.mas_left).with.offset(100*kWidth);
        make.top.equalTo(imageline3.mas_bottom).with.offset(10*kHeight);
    }];
    _arriveBtn = [com createBtn:@"明天到达" andFont:FontOfSize14 andTag:3 and:self action:@selector(pressBtn:) andColor:BlackColor];
    _arriveBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
    [self.view addSubview:_arriveBtn];
    [_arriveBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(arrive.mas_right).with.offset(20*kWidth);
        make.top.equalTo(arrive.mas_top);
        make.bottom.equalTo(arrive.mas_bottom);
        make.right.mas_equalTo(self.view.mas_right);
    }];
    UIImageView * image3 = [[UIImageView alloc]init];
    image3.image = [UIImage imageNamed:@"common_list_arrows_more"];
    [self.view addSubview:image3];
    [image3 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.view.mas_right).with.offset(-20*kWidth);
        make.centerY.equalTo(_arriveBtn.mas_centerY);
        make.size.mas_equalTo(CGSizeMake(6*kWidth, 11*kHeight));
    }];

    UIImageView * imageline4 =[[UIImageView alloc]init];
    imageline4.image = [UIImage imageNamed:@"common_list_line1"];
    [self.view addSubview:imageline4];
    [imageline4 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.view.mas_left).with.offset(0);
        make.size.mas_equalTo(CGSizeMake(Main_Width, 0.5));
        make.top.mas_equalTo(arrive.mas_bottom).with.offset(5*kHeight);
    }];

    UILabel * hold = [com createUIlabel:@"空仓位:" andFont:FontOfSize14 andColor:BlackColor];
    hold.textAlignment = NSTextAlignmentRight;
    [self.view addSubview:hold];
    [hold mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.view.mas_left).with.offset(100*kWidth);
        make.top.equalTo(imageline4.mas_bottom).with.offset(10*kHeight);
    }];
    UIImageView * imageline5 =[[UIImageView alloc]init];
    imageline5.image = [UIImage imageNamed:@"common_list_line1"];
    [self.view addSubview:imageline5];
    [imageline5 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.view.mas_left).with.offset(0);
        make.size.mas_equalTo(CGSizeMake(Main_Width, 0.5));
        make.top.mas_equalTo(hold.mas_bottom).with.offset(5*kHeight);
    }];
    
    UIButton * reduceBtn = [com createBtn:@"-" andFont:FontOfSize14 andTag:5 and:self action:@selector(pressReduceBtn) andColor:BlackColor];
    reduceBtn.backgroundColor = [UIColor cyanColor];
    reduceBtn.layer.borderWidth = 1;
    reduceBtn.layer.borderColor = RGBACOLOR(149, 149, 149, 1).CGColor;
    [self.view addSubview:reduceBtn];
    [reduceBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(hold.mas_right).with.offset(20*kWidth);
        make.top.equalTo(hold.mas_top);
        make.bottom.equalTo(hold.mas_bottom);
        make.width.mas_equalTo(50*kWidth);
    }];
    _holdNumber = [com createUIlabel:@"1" andFont:FontOfSize14 andColor:BlackColor];
    [self.view addSubview:_holdNumber];
    [_holdNumber mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(reduceBtn.mas_right).with.offset(10*kWidth);
        make.top.equalTo(reduceBtn.mas_top);
        make.bottom.equalTo(reduceBtn.mas_bottom);
    }];
    UIButton * addBtn = [com createBtn:@"+" andFont:FontOfSize14 andTag:5 and:self action:@selector(pressAddBtn) andColor:BlackColor];
    addBtn.layer.borderWidth = 1;
    addBtn.layer.borderColor = RGBACOLOR(149, 149, 149, 1).CGColor;
    [self.view addSubview:addBtn];
    [addBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(_holdNumber.mas_right).with.offset(10*kWidth);
        make.top.equalTo(_holdNumber.mas_top);
        make.bottom.equalTo(_holdNumber.mas_bottom);
        make.width.mas_equalTo(50*kWidth);
    }];

    
    
    
    UIButton * btn = [com createBtn:@"上报" andFont:FontOfSize14 andTag:20 and:self action:@selector(pressBtnWork) andColor:BlackColor];
    [self.view addSubview:btn];
    btn.layer.borderWidth = 1;
    btn.layer.borderColor = RGBACOLOR(149, 149, 149, 1).CGColor;
    btn.backgroundColor = [UIColor cyanColor];
    [btn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(backview.mas_centerX);
        make.size.mas_equalTo(CGSizeMake(Main_Width/3*2, 35*kHeight));
        make.top.mas_equalTo(imageline5.mas_bottom).with.offset(30*kHeight);
    }];

}

-(void)pressAddBtn{
    
    if (holdcount<16) {
        holdcount ++;
        _holdNumber.text = [NSString stringWithFormat:@"%d",holdcount];
    }else{
        [self createUIAlertController:@"输入的仓位过多"];
    }
    [_dicUrl setObject:[NSString stringWithFormat:@"%d",holdcount] forKey:@"emptyStore"];
}
-(void)pressReduceBtn{
    
    if (holdcount > 1) {
        holdcount --;
        _holdNumber.text = [NSString stringWithFormat:@"%d",holdcount];
    }else{
        [self createUIAlertController:@"输入的仓位过少"];
    }
    [_dicUrl setObject:[NSString stringWithFormat:@"%d",holdcount] forKey:@"emptyStore"];
}

-(void)pressBtnWork{
    
    NSLog(@"_dicUrl====%@",_dicUrl);

    [com afPostRequestWithUrlString:journey_Url parms:_dicUrl finishedBlock:^(id responseObj) {
        NSMutableDictionary * dicObj =[NSJSONSerialization JSONObjectWithData:responseObj options:NSJSONReadingMutableContainers error:nil];
        NSLog(@"%@",dicObj);
        NSString * success = [NSString stringWithFormat:@"%@",dicObj[@"success"]];
        if ([success isEqualToString:@"1"]) {
            
        }else{
            [self createUIAlertController:[NSString stringWithFormat:@"%@",dicObj[@"message"]]];
        }
        
    } failedBlock:^(NSString *errorMsg) {
    
    }];

}



-(void)pressBtn:(UIButton *)sender{
    
    switch (sender.tag) {
        case 1:
            NSLog(@"在途");
            [self pressBtnState];
            break;
        case 2:
            NSLog(@"湖南长沙");
            [self pressBtnArea];
            break;
            
        case 3:
            NSLog(@"明天到达");
            [self pressBtnArrive];
            break;

            
        default:
            break;
    }
    
    
}

-(void)pressBtnState{
    
    UIPickerView *education = [[UIPickerView alloc] init];
    ActionSheetPicker *actionSheet=[[ActionSheetPicker alloc]initWithTarget:self successAction:@selector(selectOK:) cancelAction:nil origin:education];
    education.tag = stateTAG;
    CGRect pickerFrame = CGRectMake(0, 40, actionSheet.viewSize.width, 216);
    [education setFrame:pickerFrame];
    education.delegate = self;
    education.dataSource = self;
    //pickview  左选择按钮的文字
    UIButton *leftBtn =[UIButton buttonWithType:UIButtonTypeCustom];
    [leftBtn setTitle:@"取消"forState:UIControlStateNormal];
    leftBtn.frame=CGRectMake(0, 0, 50, 45);
    [leftBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    UIBarButtonItem *leftIte=[[UIBarButtonItem alloc]initWithCustomView:leftBtn];
    //pickview    右选择按钮的文字
    UIButton *rightBtn =[UIButton buttonWithType:UIButtonTypeCustom];
    [rightBtn setTitle:@"完成" forState:UIControlStateNormal];
    rightBtn.frame=CGRectMake(0, 0, 50, 45);
    [rightBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    UIBarButtonItem *rightIte=[[UIBarButtonItem alloc]initWithCustomView:rightBtn];
    //将按钮添加到pickerview 上
    [actionSheet setDoneButton:rightIte];
    [actionSheet setCancelButton:leftIte];
    actionSheet.pickerView = education;
    actionSheet.title = @"状态选择";
    [actionSheet showActionSheetPicker];

}

-(void)pressBtnArea{
   
    _provienceArray = nil;
    _cityArray = nil;
    _areaArray = nil;
    
    _provienceArray = [AREA selectAreaWithFArea:nil withTarea:nil withFarea:1];
    _cityArray = [AREA selectAreaWithFArea:@"北京市" withTarea:nil withFarea:2];
    _areaArray = [AREA selectAreaWithFArea:@"北京市" withTarea:@"市辖区" withFarea:3];
    
//    UIImageView * image = (UIImageView*)[self.view viewWithTag:1000];
//    image.transform = CGAffineTransformMakeRotation(M_PI_2);
    UIPickerView *education = [[UIPickerView alloc] init];
    ActionSheetPicker *actionSheet=[[ActionSheetPicker alloc]initWithTarget:self successAction:@selector(selectOK:) cancelAction:nil origin:education];
    education.tag = areaTAG;
    CGRect pickerFrame = CGRectMake(0, 40, actionSheet.viewSize.width, 216);
    [education setFrame:pickerFrame];
    education.delegate = self;
    education.dataSource = self;
    //pickview  左选择按钮的文字
    UIButton *leftBtn =[UIButton buttonWithType:UIButtonTypeCustom];
    [leftBtn setTitle:@"取消"forState:UIControlStateNormal];
    leftBtn.frame=CGRectMake(0, 0, 50, 45);
    [leftBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    UIBarButtonItem *leftIte=[[UIBarButtonItem alloc]initWithCustomView:leftBtn];
    //pickview    右选择按钮的文字
    UIButton *rightBtn =[UIButton buttonWithType:UIButtonTypeCustom];
    [rightBtn setTitle:@"完成" forState:UIControlStateNormal];
    rightBtn.frame=CGRectMake(0, 0, 50, 45);
    [rightBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    UIBarButtonItem *rightIte=[[UIBarButtonItem alloc]initWithCustomView:rightBtn];
    //将按钮添加到pickerview 上
    [actionSheet setDoneButton:rightIte];
    [actionSheet setCancelButton:leftIte];
    actionSheet.pickerView = education;
    actionSheet.title = @"地址选择";
    [actionSheet showActionSheetPicker];
}

-(void)pressBtnArrive{
    
    UIPickerView *education = [[UIPickerView alloc] init];
    ActionSheetPicker *actionSheet=[[ActionSheetPicker alloc]initWithTarget:self successAction:@selector(selectOK:) cancelAction:nil origin:education];
    education.tag = arriveTAG;
    CGRect pickerFrame = CGRectMake(0, 40, actionSheet.viewSize.width, 216);
    [education setFrame:pickerFrame];
    education.delegate = self;
    education.dataSource = self;
    //pickview  左选择按钮的文字
    UIButton *leftBtn =[UIButton buttonWithType:UIButtonTypeCustom];
    [leftBtn setTitle:@"取消"forState:UIControlStateNormal];
    leftBtn.frame=CGRectMake(0, 0, 50, 45);
    [leftBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    UIBarButtonItem *leftIte=[[UIBarButtonItem alloc]initWithCustomView:leftBtn];
    //pickview    右选择按钮的文字
    UIButton *rightBtn =[UIButton buttonWithType:UIButtonTypeCustom];
    [rightBtn setTitle:@"完成" forState:UIControlStateNormal];
    rightBtn.frame=CGRectMake(0, 0, 50, 45);
    [rightBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    UIBarButtonItem *rightIte=[[UIBarButtonItem alloc]initWithCustomView:rightBtn];
    //将按钮添加到pickerview 上
    [actionSheet setDoneButton:rightIte];
    [actionSheet setCancelButton:leftIte];
    actionSheet.pickerView = education;
    actionSheet.title = @"到达日起选择";
    [actionSheet showActionSheetPicker];
    

}


-(void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component

{
    NSInteger ss = [pickerView selectedRowInComponent:0];
    
    if (pickerView.tag == areaTAG) {
        NSInteger dd = [pickerView selectedRowInComponent:1];
        switch (component) {
            case 0:
            {
                NSDictionary *dict = [_provienceArray objectAtIndex:row];
                NSString *code = MySetValue(dict, @"provinceName");
                if (code.length > 0)
                {
                    _cityArray = [AREA selectAreaWithFArea:code withTarea:nil withFarea:2];
                    [pickerView reloadComponent:1];
                    NSDictionary *cityDict = [_cityArray objectAtIndex:dd];
                    NSString * cityFcode = MySetValue(cityDict, @"cityName");
                    if (cityFcode.length > 0)
                    {
                        _areaArray = [AREA selectAreaWithFArea:code withTarea:cityFcode withFarea:3];
                        [pickerView reloadComponent:2];
                    }
                }
            }
                break;
            case 1:
            {
                NSDictionary *dict = [_cityArray objectAtIndex:row];
                NSString *code = MySetValue(dict, @"cityName");
                
                NSDictionary * dics = [_provienceArray objectAtIndex:ss];
                NSString * str = MySetValue(dics, @"provinceName");
                
                if (code.length > 0) {
                    _areaArray = [AREA selectAreaWithFArea:str withTarea:code withFarea:3];
                    [pickerView reloadComponent:2];
                }
            }
                break;
            case 2:{
                
            }
                break;
                
            default:
                break;
        }

    }

    else if (pickerView.tag == arriveTAG){
        NSLog(@"%@",_arriveArr[ss]);
    }else{
        NSLog(@"%@",_stateArr[ss]);
    }

}


- (void)selectOK:(id)sender{

    UIPickerView *pick = sender;
    
    if (pick.tag == areaTAG) {
        NSInteger row = [pick selectedRowInComponent:0];
        NSDictionary *dict = [_provienceArray objectAtIndex:row];
        NSString *provinceName = MySetValue(dict, @"provinceName");//省名称
        NSString *provinceCode = MySetValue(dict, @"provinceCode");//省编码
        [_dicUrl setObject:provinceName forKey:@"receiptProvinceName"];
        [_dicUrl setObject:provinceCode forKey:@"receiptProvinceCode"];

        NSInteger row1 = [pick selectedRowInComponent:1];
        NSDictionary *dict1 = [_cityArray objectAtIndex:row1];
        NSString *cityName = MySetValue(dict1, @"cityName");//市名称
        NSString *citycode = MySetValue(dict1, @"cityCode");//市编码
        [_dicUrl setObject:cityName forKey:@"receiptCityName"];
        [_dicUrl setObject:citycode forKey:@"receiptCityCode"];

        
        NSInteger row2 = [pick selectedRowInComponent:2];
        NSDictionary *dict2 = [_areaArray objectAtIndex:row2];
        NSString *countyName = MySetValue(dict2, @"countyName");//县名称
        NSString * countycode = MySetValue(dict2, @"countyCode");//县编码
        [_dicUrl setObject:countyName forKey:@"receiptCountyName"];
        [_dicUrl setObject:countycode forKey:@"receiptCountyCode"];

        
        NSString * string = [NSString stringWithFormat:@"%@%@%@",provinceName,cityName,countyName];
        [_destinationBtn setTitle:string forState:UIControlStateNormal];
        //    UIImageView * image = (UIImageView*)[self.view viewWithTag:1000];
        //    image.transform = CGAffineTransformMakeRotation(0);
    }
    
    else if (pick.tag == arriveTAG ){
        NSInteger row = [pick selectedRowInComponent:0];
        [_arriveBtn setTitle:_arriveArr[row] forState:UIControlStateNormal];
        //预计
        
        NSDate *  senddate=[NSDate date];
        NSCalendar *gregorian = [[NSCalendar alloc] initWithCalendarIdentifier:NSCalendarIdentifierGregorian];
        NSDateComponents *components = [gregorian components:NSCalendarUnitWeekday | NSCalendarUnitYear | NSCalendarUnitMonth | NSCalendarUnitDay fromDate:senddate];
        if (row == 0) {
            [components setDay:([components day])];
        }else if (row == 1){
            [components setDay:([components day]+1)];
        }else{
            [components setDay:([components day]+2)];
        }
        NSDate *beginningOfWeek = [gregorian dateFromComponents:components];
        NSDateFormatter *dateday = [[NSDateFormatter alloc] init];
        [dateday setDateFormat:@"yyyy/MM/dd"];
        NSString * dataStri = [NSString stringWithFormat:@"%@",[dateday stringFromDate:beginningOfWeek]];;
        
        [_dicUrl setObject:dataStri forKey:@"predictArrive"];
        
    }else{
        
        NSInteger row = [pick selectedRowInComponent:0];
        if (row == 0) {
            [_dicUrl setObject:@"10" forKey:@"status"];
        }else if (row == 1){
            [_dicUrl setObject:@"20" forKey:@"status"];
        }else{
            [_dicUrl setObject:@"30" forKey:@"status"];
        }
        [_stateBtn setTitle:_stateArr[row] forState:UIControlStateNormal];
    }
}
//  跳出的pickerview  显示列数
-(NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView
{
    
    return (pickerView.tag == areaTAG)?3:1;
}
//显示pickerview 每个视图的行数
-(NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component

{
    
    switch (pickerView.tag) {
        case stateTAG:
            return _stateArr.count;
            break;
        case arriveTAG:
            return _arriveArr.count;
            break;
        case areaTAG:{
            switch (component) {
                case 0:
                    return _provienceArray.count;
                    break;
                case 1:
                    return _cityArray.count;
                    break;
                case 2:
                    return _areaArray.count;
                    break;
                default:
                    break;
            }
        }
            break;

        default:
            break;
    }
    
    return 0;
}

//显示每个pickerview  每行的具体内容

-(UIView*)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view

{
    
    
    UILabel *lable  = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 100, 30)];
    lable.adjustsFontSizeToFitWidth = YES;
    lable.textAlignment = NSTextAlignmentCenter;
    
    switch (pickerView.tag) {
        case stateTAG:
            lable.text = [NSString stringWithFormat:@"%@",_stateArr[row]];
            break;
        case arriveTAG:
            lable.text = [NSString stringWithFormat:@"%@",_arriveArr[row]];
            break;
        case areaTAG:
            switch (component) {
                case 0:{
                    NSDictionary *dict = [_provienceArray objectAtIndex:row];
                    lable.text = MySetValue(dict, @"provinceName");
                }
                    
                    break;
                case 1:{
                    NSDictionary *dict = [_cityArray objectAtIndex:row];
                    lable.text = MySetValue(dict, @"cityName");
                }
                    break;
                case 2:{
                    NSDictionary *dict = [_areaArray objectAtIndex:row];
                    lable.text = MySetValue(dict, @"countyName");
                }
                    break;
                default:
                    break;
            }
            break;
        default:
            break;
    }
    return lable;
}




- (void)initCompleteBlock
{
    __weak DriverCourseVC *wSelf = self;
    self.completionBlock = ^(CLLocation *location, AMapLocationReGeocode *regeocode, NSError *error)
    {
        if (error)
        {
            NSLog(@"locError:{%ld - %@};", (long)error.code, error.localizedDescription);
            
            if (error.code == AMapLocationErrorLocateFailed)
            {
                return;
            }
        }
        
        if (location)
        {
            if (regeocode)
            {
//                [wSelf.displayLabel setText:[NSString stringWithFormat:@"%@ \n %@-%@-%.2fm", regeocode.formattedAddress,regeocode.citycode, regeocode.adcode, location.horizontalAccuracy]];
                
                [wSelf.placeBtn setTitle:[NSString stringWithFormat:@"%@ \n %@-%@-%.2fm", regeocode.formattedAddress,regeocode.citycode, regeocode.adcode, location.horizontalAccuracy] forState:UIControlStateNormal];
                [wSelf.dicUrl setObject:[NSString stringWithFormat:@"%f",location.coordinate.latitude] forKey:@"latitude"];
                [wSelf.dicUrl setObject:[NSString stringWithFormat:@"%f",location.coordinate.longitude] forKey:@"longitude"];
                NSString * address = [NSString stringWithFormat:@"%@%@%@",regeocode.province,regeocode.city,regeocode.district];
                [wSelf.dicUrl setObject:address forKey:@"currentAddrDesc"];

            }
            else
            {
                [wSelf.displayLabel setText:[NSString stringWithFormat:@"lat:%f;lon:%f \n accuracy:%.2fm", location.coordinate.latitude, location.coordinate.longitude, location.horizontalAccuracy]];
            }
        }
    };
}
- (void)configLocationManager
{
    self.locationManager = [[AMapLocationManager alloc] init];
    
    [self.locationManager setDelegate:self];
    
    [self.locationManager setDesiredAccuracy:kCLLocationAccuracyHundredMeters];
    
    [self.locationManager setPausesLocationUpdatesAutomatically:NO];
    
    [self.locationManager setAllowsBackgroundLocationUpdates:YES];
    
    [self.locationManager setLocationTimeout:LocationTimeout];
    
    [self.locationManager setReGeocodeTimeout:ReGeocodeTimeout];
    
}

- (void)initDisplayLabel
{
    _displayLabel = [[UILabel alloc] init];
    _displayLabel.backgroundColor  = [UIColor clearColor];
    _displayLabel.textColor        = [UIColor blackColor];
    _displayLabel.textAlignment = NSTextAlignmentCenter;
    _displayLabel.numberOfLines = 0;
    [_displayLabel setFrame:[UIScreen mainScreen].bounds];
    [self.view addSubview:_displayLabel];
}

- (void)returnAction
{
    [self cleanUpAction];
    
    self.completionBlock = nil;
    
    [self.navigationController popViewControllerAnimated:YES];
}
- (void)cleanUpAction
{
    [self.locationManager stopUpdatingLocation];
    
    [self.locationManager setDelegate:nil];
}
- (void)reGeocodeAction
{
    [self.locationManager requestLocationWithReGeocode:YES completionBlock:self.completionBlock];
}

- (void)locAction
{
    [self.locationManager requestLocationWithReGeocode:NO completionBlock:self.completionBlock];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
 -(void)createUIAlertController:(NSString*)title
 
{
    UIAlertController * alert =[UIAlertController alertControllerWithTitle:@"提示" message:title preferredStyle:UIAlertControllerStyleAlert];
    UIAlertAction * action =[UIAlertAction actionWithTitle:@"确认" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        
        
    }];
    UIAlertAction * action1 =[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
    }];
    [alert addAction:action1];
    [alert addAction:action];
    [self presentViewController:alert animated:YES completion:nil];
}
*/
@end
